<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>demo2</title>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script src="js/underscore.js" type="text/javascript"></script>
    <script src="js/backbone.js" type="text/javascript"></script>
    <!-- <script type="text/javascript" src="assertEqual.js"></script> -->
</head>

<body>
    <script type="text/javascript">
    // var User = Backbone.Model.extend({
    //     initialize: function() {}
    // });
    // console.log(User);

    //*******************
    // var User = Backbone.Model.extend({
    //     //实例属性
    //     instanceProperty: 'foo'
    // }, {
    //     //类属性
    //     classProperty: 'bar'
    // });
    // console.log(User.instanceProperty);
    // console.log(User.classProperty);
    // assertEqual(User.instanceProperty, 'foo');
    // assertEqual(User.classProperty, 'bar');

    //******************
    // var User = Backbone.Model.extend({
    //     initialize: function(name) {
    //         this.set({
    //             name: name
    //         });
    //     }
    // });
    // var user = new User('刀狂剑痴');
    // console.log(user.get('name'));

    // user.set({
    //     name: '叶叶叶叶'
    // });
    // user.get('name'); //叶小钗
    // user.attributes; //{name: '叶小钗'}
    // console.log(user.get('name'));
    // console.log(user.attributes);
    // assertEqual(user.get('name'), '刀狂剑痴');
    //******************

    var User = Backbone.Model.extend({
        validate: function(attr) {
            if (!attr.name || attr.name.length < 3) {
                return '名称长度过短';
            }
        }
    });
    var user = new User();
    user.bind('error', function(model, error) {
        //错误处理
    });
    user.set({
        name: '0'
    });
    //给特定集合添加一个错误处理程序
    user.set({
        name: '0'
    }, {
        error: function(model, error) {}
    });
    </script>
</body>

</html>
